<?php
if ($id) {
	$query	=	"SELECT * from comments where `to`=$id and (type=2 or type=0)";
	$result = mysql_query($query);
	xmlwriter_start_element($xml,"messages");
	xmlwriter_write_element($xml,"new",	mysql_num_rows($result) );
	$query	=	"SELECT * from comments where `to`=$id ";
	$result = mysql_query($query);
	xmlwriter_write_element($xml,"total",	mysql_num_rows($result) );
	if (mysql_num_rows($result)){ 
		
		while ($message = mysql_fetch_array($result)) {
			xmlwriter_start_element($xml,"message");
			if ($message['type']==0 || $message['type']==1)
				xmlwriter_write_element($xml,"type","comment");
			if ($message['type']==2 || $message['type']==3)	
				xmlwriter_write_element($xml,"type","pm");
			xmlwriter_write_element($xml,"read", $message['type'] % 2 );	
			xmlwriter_write_element($xml,"id",	$message['id'] );	
			xmlwriter_write_element($xml,"text",	$message['text'] );	
			xmlwriter_end_element($xml);
		}
	}
	xmlwriter_end_element($xml);
} else {
xmlwriter_write_element($xml,"error",	"Not logged in");
header("403 You need to be logged in" );
}

				

?>
